package com.pigdogbay.androidutils.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public final class StringUtils
{
    public static final String LOWERCASE_ALPHABET = "abcdefghijklmnopqrstuvwxyz";

	public static String WordSort(String word)
	{
		char[] letters = word.toCharArray();
		Arrays.sort(letters);		
		return new String(letters);
	}
    /*
     * Returns all the words that are one letter less, eg
     * ABCD returns BCD, ACD, ABD, ABC
     * 
     */
	public static List<String> GetSubWords(String word)
	{
		ArrayList<String> subwords = new ArrayList<String>();
		int len = word.length();
		if (len>1)
		{
			for (int i=0;i<len;i++)
			{
				StringBuilder sb = new StringBuilder(word);
				sb.deleteCharAt(i);
				subwords.add(sb.toString());
			}
		}
		return subwords;
	}
	/*
	 * Performs the reverse operation to GetSubWords
	 */
	public static char GetMissingLetter(String word, String subWord)
	{
		String remainder = SubtractChars(word, subWord);
		return remainder.charAt(0);
	}

	/*
	 * Subtracts the letters of littleword from bigword
	 * Returns: a string of the remainder chars
	 */
	public static String SubtractChars(String bigword, String littleword)
	{
		StringBuilder sbBig = new StringBuilder(bigword);
		for (char c : littleword.toCharArray())
		{
			for (int i=0;i<sbBig.length();i++)
			{
				if (sbBig.charAt(i)==c)
				{
					sbBig.deleteCharAt(i);
					break;
				}
			}
		}
		return sbBig.toString();
	}
	/*
	 * Checks if the word contains any of the banned letters.
	 * 
	 * Returns true if word does not contain any of the banned letters
	 * 
	 */
	public static boolean DoesNotContainBannedLetters(String word, char[] bannedLetters)
	{
        char[] chars = word.toCharArray();
        for(char c : bannedLetters)
        {
            for (int i = 0; i < chars.length; i++)
            {
                if (c == chars[i])
                {
                    return false;
                }
            }
        }
        return true;		
	}
	
	
}
